using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using SceneEngine;

namespace SceneEditor.UI
{
    public partial class Editor : KryptonForm
    {
        private int previewWindowHeight;

        public IntPtr ViewportHandle { get { return Viewport.Handle; } }

        public AddLightForm AddLightForm = new AddLightForm();
        public AddAssetForm AddAssetForm = new AddAssetForm();

        public ToolStripControlHost keyframeDisplayHost;

        public bool Resizing;

        public Editor()
        {
            InitializeComponent();

            cbOrientation.SelectedIndex = 0;
            cbOrigin.SelectedIndex = 0;
            cbRotationMode.SelectedIndex = 0;
            cbPlacement.SelectedIndex = 0;

            TopMost = false;

            ResizeBegin += new EventHandler(Editor_ResizeBegin);
            ResizeEnd += new EventHandler(Editor_ResizeEnd);

            previewWindowHeight = kryptonHeaderGroup5.Height;
        }

        private void Editor_ResizeBegin(object sender, EventArgs e)
        {
            Resizing = true;
        }
        private void Editor_ResizeEnd(object sender, EventArgs e)
        {
            Resizing = false;
        }

        private void tsClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Viewport_Click(object sender, EventArgs e)
        {
            Viewport.Select();
        }

        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            this.BeginInvoke(new TreeNodeMouseClickEventHandler(DelayedClick), sender, e);
        }
        private void DelayedClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            Viewport.Focus();
        }

        private void Editor_FormClosing(object sender, FormClosingEventArgs e)
        {
            Preferences.Default.Save();
        }

        private void viewSceneToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            toolControl.SelectedIndex = 0;
        }
        private void viewModelsToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            toolControl.SelectedIndex = 1;
        }
        private void viewPropertiesToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            toolControl.SelectedIndex = 2;
        }

        private void btnRotate_CheckedChanged(object sender, EventArgs e)
        {
            toolStripSeparator6.Visible = lblGroup.Visible =
                cbRotationMode.Visible = lblRotateOrigin.Visible =
                cbOrigin.Visible = btnRotate.Checked;
        }

        private void buttonSpecHeaderGroup2_Click(object sender, EventArgs e)
        {
            tbModels.SuspendLayout();

            if (kryptonHeaderGroup5.Collapsed == false)
            {
                kryptonHeaderGroup5.Height = previewWindowHeight;
            }
            else
            {
                kryptonHeaderGroup5.Height = kryptonHeaderGroup5.PreferredSize.Height;
            }

            tbModels.ResumeLayout();
        }
    }
}